﻿using System.Linq;
using System.Web.Mvc;
using ZQNB.BaseLib.Core.Models;
using ZQNB.Common;
using ZQNB.Common.Ioc;
using ZQNB.Common.Web;
using ZQNB.Web.Common.Contexts;

namespace ZQNB.Web.Common.Helpers
{
    public class BsStyleVo
    {
        public string InnerContainerStyle { get; set; }
        public string ContainerStyle { get; set; }
        public string ThemeCssUrl { get; set; }
    }

    public class BsStyleHelper
    {
        private readonly INbSiteContextProvider _nbSiteContextProvider;

        public BsStyleHelper(INbSiteContextProvider nbSiteContextProvider)
        {
            _nbSiteContextProvider = nbSiteContextProvider;
        }

        public BsStyleVo GetBsStyleVo()
        {
            BsStyleVo vo = new BsStyleVo();

            BsSetting bsSetting = _nbSiteContextProvider.GetBsSetting();
            var insideContainerStyle = bsSetting.InsideContainer ? "container " : "container-fluid ";
            var responsiveStyle = bsSetting.Responsive ? "" : "fixed-container";
            var theContainerStyle = string.Format("{0}{1}", insideContainerStyle, responsiveStyle).TrimEnd(' ');
            vo.InnerContainerStyle = insideContainerStyle; ;
            vo.ContainerStyle = theContainerStyle;

            UrlHelper currentUrlHelper = MvcHelper.GetCurrentUrlHelper();
            var cssStyle = currentUrlHelper.Content("~/Content/libs/bootstrap/css/bootstrap.css");


            var currentTheme = bsSetting.Themes.FirstOrDefault(x => x.Name.NbEquals(bsSetting.Theme));
            if (currentTheme != null)
            {
                cssStyle = currentUrlHelper.Content(currentTheme.Path);
            }
            vo.ThemeCssUrl = cssStyle;

            return vo;
        }
    }
}